package com.systop.common.util;

import java.util.List;

/**
 * <p>ClassName: PageResult</p>
 * <p>Description:</p>
 *
 * @author 孙伟光
 * @version 1.0
 * @date 2020/3/31 16:38
 */
public class PageResult<T> {
    /**
     * 返回消息
     */
    private String msg;
    /**
     * 返回编码
     */
    private Integer code;
    /**
     * 返回条数
     */
    private long count;
    /**
     * 返回数据
     */
    private List<T> data;

    public PageResult() {
        this.code = 200;
        this.msg = "OK";
        this.count = 0;
        this.data = null;
    }

    public PageResult(List<T> data, long count) {
        this.code = 200;
        this.msg = "OK";
        this.count = count;
        this.data = data;
    }

    public PageResult(String msg, Integer code) {
        this.msg = msg;
        this.code = code;
        this.count = 0;
        this.data = null;
    }

    /**
     * 传递消息和编码
     * @param msg 消息
     * @param code 编码
     * @param <T> 类型
     * @return PageResult对象
     */
    public static <T> PageResult<T> build(String msg, Integer code){
        return new PageResult<>(msg, code);
    }

    /**
     * 传递数据和条数
     * @param data 数据集合
     * @param count 条数
     * @param <T> 类型
     * @return PageResult对象
     */
    public static <T> PageResult<T> ok(List<T> data, long count){
        return new PageResult<>(data, count);
    }

    //getter and setter方法

    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }
    public void setCode(Integer code) {
        this.code = code;
    }

    public long getCount() {
        return count;
    }
    public void setCount(long count) {
        this.count = count;
    }

    public List<T> getData() {
        return data;
    }
    public void setData(List<T> data) {
        this.data = data;
    }
}
